using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.Presenters.Presenters.ListManager;
using CMS.Web;
using CMS.Presenters.Views.ListManager;
using CMS.Core.Domain;
using CMS.Data;

namespace CMS.Web.ListManager
{
    public partial class EditCauHinh : BaseUserControl, IEditCauHinhBCView
    {
        private EditCauHinhBCPresenter presenter;
        private CauHinhBC obj;
        public string TenPhieu = "";
        int index = 0;

        public EditCauHinh()
        {
            this.presenter = new EditCauHinhBCPresenter(this, NHibernateDaoFactory.Instance.GetCauHinhBCDao());
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            // For Ajax
            //this.RaiseClientEvent();

            presenter.InitViewForEditing(int.Parse(Request.QueryString["objID"]), IsPostBack);
            this.obj = presenter.getByID(int.Parse(Request.QueryString["objID"]));
        }        
        
        public string Message
        {
            set { //lblMessage.Text = value; 
            }
        }

        public CauHinhBC ObjToUpdate
        {
            get
            {
                if (this.obj != null)
                {
                    this.obj.TenCoQuan = txtTenCoQuan.Text.Trim();
                    obj.Muc1 = txtMuc1.Text.Trim();
                    obj.Muc2 = txtMuc2.Text.Trim();
                    obj.PhongTaoPhieu = txtPhongTaoPhieu.Text.Trim();
                    obj.SoHieu = txtSoHieu.Text.Trim();
                    obj.VeViec = txtVeViec.Text.Trim();                    
                }
                return this.obj;
            }
            set
            {
                if (value == null) throw new ArgumentNullException("ObjToUpdate may not be null");

                hidID.Value = Convert.ToString(value.ID);
                txtTenCoQuan.Text = value.TenCoQuan;
                txtMuc1.Text = value.Muc1;
                txtMuc2.Text = value.Muc2;
                txtPhongTaoPhieu.Text = value.PhongTaoPhieu;
                txtSoHieu.Text = value.SoHieu;
                txtVeViec.Text = value.VeViec;
                TenPhieu = value.TenPhieu;
            }
        }

        #region Button Members
        protected void btnOK_Click(object sender, EventArgs e)
        {
            presenter.UpdateObj(Page.IsValid);
            this.btnCancel_Click(this, null);
        }

        protected void btnOKC_Click(object sender, EventArgs e)
        {
            presenter.UpdateObj(Page.IsValid);
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect(BaseUrl + "&action=VIEW");
        }
        #endregion
    }
}